package com.tanglongan.designPattern.dp20_strategy.demo00.better.impl;

import com.tanglongan.designPattern.dp20_strategy.demo00.better.ICouponDiscount;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 满减优惠计算
 */
public class MJCouponDiscount implements ICouponDiscount<Map<String, String>> {

    @Override
    public BigDecimal discountAmount(Map<String, String> couponInfo, BigDecimal skuPrice) {
        String x = couponInfo.get("x");
        String o = couponInfo.get("n");
        //小于商品金额，直接返回原价格
        if (skuPrice.compareTo(new BigDecimal(x)) < 0) return skuPrice;
        //减去优惠金额
        BigDecimal discountAmount = skuPrice.subtract(new BigDecimal(o));
        if (discountAmount.compareTo(BigDecimal.ZERO) < 1) return BigDecimal.ONE;
        return discountAmount;
    }
}
